package com.lt.utils;

public class GetTimeString {
    private final String strTime;
    private String[] TimeStr;
    private Integer[] priTime;
    private final Integer[] nextTime;
    private Integer[] startTime;
    private String[] LongStr;
    private Integer[] StrLong;
    private Integer[] CurrentTimeArray;


    /***
     *
     * @param time 获取JSON数组数据
     */
    public GetTimeString(String time) {
        strTime = time;
        TimeStr = new String[2];
        nextTime = new Integer[3];
        StrLong = new Integer[6];
    }

    //处理识别中字符串
    public Integer[] getStartTime() {
        if (strTime.indexOf("|") > 0 && strTime.indexOf("-") > 0 && strTime.indexOf(":") > 0) {
            LongStr = strTime.split("-|:|\\|");
            for (int i = 0; i < LongStr.length; i++) {
                StrLong[i] = Integer.parseInt(LongStr[i]);
            }
        } else {
            StrLong = new Integer[]{1970, 1, 1, 0, 0, 0};
        }
        return StrLong;
    }

    //解决从识别中获取的字符串
    public String[] getTimeString() {

        TimeStr = strTime.split("\\|");
        return TimeStr;
    }

    public Integer[] getPriTime() {
        getTimeString();
        String[] str;
        str = TimeStr[0].split("-");
        for (int i = 0; i < str.length; i++) {
            priTime[i] = Integer.parseInt(str[i]);
        }

        return priTime;
    }

    public Integer[] getNextTime() {
        getTimeString();
        String[] str;
        str = TimeStr[1].split(":");
        for (int i = 0; i < str.length; i++) {
            nextTime[i] = Integer.parseInt(str[i]);
        }
        return nextTime;
    }

    //获取从本地获取的字符串
    public String[] getNowTimeString() {
        TimeStr = strTime.split(" ");
        return TimeStr;
    }

    //前一段
    public Integer[] getNowPriTime() {
        getNowTimeString();
        String[] str;
        priTime = new Integer[3];
        str = TimeStr[0].split("年|月|日");
        for (int i = 0; i < str.length; i++) {
            priTime[i] = Integer.parseInt(str[i]);
        }

        return priTime;
    }

    //后一段
    public Integer[] getNowNextTime() {
        getNowTimeString();
        String[] str;
        Integer[] NextTime = new Integer[3];
        str = TimeStr[1].split(":");
        for (int i = 0; i < str.length; i++) {
            NextTime[i] = Integer.parseInt(str[i]);
        }

        return NextTime;
    }

    /***
     * 获取当前时间数组，用于比较
     * @return
     */
    public Integer[] getCurrentTimeArray() {
        CurrentTimeArray = new Integer[6];
        Integer[] p = new Integer[3];
        Integer[] n = new Integer[3];
        n = getNowPriTime();
        p = getNowNextTime();
        for (int i = 0; i < n.length; i++) {
            CurrentTimeArray[i] = n[i];
        }

        for (int i = 0; i < p.length; i++) {
            CurrentTimeArray[3 + i] = p[i];
        }


        return CurrentTimeArray;

    }

}
